package cn.wolfcode.plus.mapper;

import cn.wolfcode.plus.domain.Employee;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

/**
 * Author wyy
 * Date 2021/2/1 9:03
 **/
@Mapper
public interface EmployeeMapper extends BaseMapper<Employee> {
    //查所有员工
    @Select("select e.*, d.id d_id, d.name d_name, d.sn d_sn from employee e " +
            "left join department d on e.dept_id = d.id")
    @Results({
            @Result(column="d_id", property = "dept.id"),
            @Result(column="d_name", property = "dept.name"),
            @Result(column="d_sn", property = "dept.sn")
    })
    IPage<Employee> selectByAnnoJoinDept(IPage<Employee> page, @Param(Constants.WRAPPER) Wrapper<Employee> queryWrapper);

    //登录校验
    @Select("select e.* from employee e where username = #{username} and password = #{password}")
    Employee checkLogin(@Param("username") String username, @Param("password") String password);

}
